package com.czgj.JGB28181.message.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.czgj.JGB28181.request.SipLayer;

@Configuration
@EnableConfigurationProperties(ConfigProperties.class)
public class SipLayerConfig {

    private Logger logger = LoggerFactory.getLogger(getClass());


    /**
     * 内网ip
     */
    @Value("${config.listenIp}")
    private String listenIp;

    /**
     * 服务端口
     */
    @Value("${config.listenPort}")
    private int listenPort;

    /**
     * 媒体服务器的 SIP 服务ID
     */
    @Value("${config.sipId}")
    private String sipId;

    /**
     * 媒体服务器 SIP 服务的域
     */
    @Value("${config.sipRealm}")
    private String sipRealm;

    /**
     * 密码
     */
    @Value("${config.password}")
    private String password;

    /**
     * 流媒体IP
     */
    @Value("${config.streamMediaIp}")
    private String streamMediaIp;

    /**
     * 初始化 sipLayer 对象
     *
     * @return 返回对象
     */
    @Bean
    public SipLayer sipLayer() {
//      1 : 创建 sipLayer 对象
        SipLayer sipLayer = new SipLayer(sipId, sipRealm, password, listenIp, listenPort, streamMediaIp);
//      2 :启动 sipLayer 服务
        boolean startStatus = sipLayer.startServer();
        if (startStatus) {
            logger.info("Sip Server 启动成功 port {}", listenPort);
        } else {
            logger.info("Sip Server 启动失败");
        }
        return sipLayer;
    }
}
